{{- if (.Values.global.enabledModules | has "operator-prometheus-crd") }}
  {{- range $version := .Values.istio.internal.operatorVersionsToInstall }}
    {{- $versionInfo := get $.Values.istio.internal.versionMap $version }}
    {{- $revision := get $versionInfo "revision" }}
---
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: istiod-{{ $revision }}
  namespace: d8-monitoring
  {{- include "helm_lib_module_labels" (list $ (dict "app" "istiod" "prometheus" "main")) | nindent 2 }}
spec:
  jobLabel: app
  selector:
    matchLabels:
      app: istiod
      istio.io/rev: {{ $revision }}
      operator.istio.io/component: Pilot
  namespaceSelector:
    matchNames:
    - d8-{{ $.Chart.Name }}
  endpoints:
  - port: http-monitoring
    relabelings:
    - regex: endpoint
      action: labeldrop
    - targetLabel: tier
      replacement: cluster
    - action: replace
      replacement: $1
      sourceLabels:
      - __meta_kubernetes_pod_label_app
      targetLabel: app
    - sourceLabels: [__meta_kubernetes_endpointslice_endpoint_conditions_ready]
      regex: "true"
      action: keep
  {{- end }}
{{- end }}
